package com.lh0811.forge.dependency.basic_web.exception;


import com.lh0811.forge.dependency.basic_web.response.ServerResponse;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 自定义异常处理
 */
@Slf4j
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class CommonException extends Exception {

    private Throwable error;

    private ServerResponse serverResponse;

    public static CommonException create(ServerResponse responseEntity) {
        CommonException exception = new CommonException();
        exception.serverResponse = responseEntity;
        return exception;
    }

    public static CommonException create(Throwable error, ServerResponse responseEntity) {
        log.error("异常拦截", error);
        CommonException exception = new CommonException();
        exception.serverResponse = responseEntity;
        exception.error = error;
        return exception;
    }

}
